package Hello_annotation;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @Grup:Hello
 * @Auther:cola
 * @Data:2021/4/17-2021-04-14:16
 * @version:1.0
 * 打印服务
 *
 */
@ComponentScan
public class Application2 {
    public static void main(String[] args) {
        System.out.println("application");
        /*//创建打印机对象
        MessagePrinter printer = new MessagePrinter();
        //创建消息服务对象
        MessageService service = new MessageService();
        //设置打印机对象的service属性
        printer.setService(service);
        //打印消息
        printer.printMessage();*/

        //初始化spring容器
        ApplicationContext context=new AnnotationConfigApplicationContext(Application2.class);
        //从容器中获取Messageprinter对象
        MessagePrinter printer = context.getBean(MessagePrinter.class);
        //从容器中获取MessageService对象
        //MessageService service = context.getBean(MessageService.class);
        //System.out.println(printer);
        //System.out.println(service);
        //设置打印机对象的service属性
        //printer.setService(service);
        //打印消息
        printer.printMessage();
    }

}
